package com.erps.db;

import java.util.HashMap;
import java.util.Map;

import com.erps.CommonUtils.Config;
import com.erps.CommonUtils.StringEx;

public class MDBConfig {
	private static Map<String, MDBConfig> DB = new HashMap<String, MDBConfig>();
	private String DBDriver = "";
	private int MAX = 100;
	private String ConnStr = "";
	private String UserID = "";
	private String Password = "";
	private String DateKey = "";
	private String ValidQuery = "";

	public String getDBDriver() {
		return DBDriver;
	}

	public void setDBDriver(String dBDriver) {
		DBDriver = dBDriver;
	}

	public int getMAX() {
		return MAX;
	}

	public void setMAX(int mAX) {
		MAX = mAX;
	}

	public String getConnStr() {
		return ConnStr;
	}

	public void setConnStr(String connStr) {
		ConnStr = connStr;
	}

	public String getUserID() {
		return UserID;
	}

	public void setUserID(String userID) {
		UserID = userID;
	}

	public String getPassword() {
		return Password;
	}

	public void setPassword(String password) {
		Password = password;
	}

	public String getDateKey() {
		return DateKey;
	}

	public void setDateKey(String dateKey) {
		DateKey = dateKey;
	}

	public String getValidQuery() {
		return ValidQuery;
	}

	public void setValidQuery(String validQuery) {
		ValidQuery = validQuery;
	}

	public static MDBConfig readConfig(String cKeyID) {
		MDBConfig vCfg = DB.get(cKeyID);
		if (vCfg == null) {
			vCfg = new MDBConfig();
			vCfg.setDBDriver(Config.ReadString(cKeyID + ".DBDriver", ""));
			vCfg.setConnStr(Config.ReadString(cKeyID + ".ConnStr", ""));
			vCfg.setUserID(Config.ReadString(cKeyID + ".UserID", ""));
			vCfg.setPassword(Config.ReadString(cKeyID + ".Password", ""));
			vCfg.setDateKey(Config.ReadString(cKeyID + ".DateKey", ""));
			vCfg.setValidQuery(Config.ReadString(cKeyID + ".ValidQuery", ""));
			String cMaxConnection = Config.ReadString(
					cKeyID + ".MaxConnection", "100");
			vCfg.setMAX(StringEx.getInt(cMaxConnection, 100));
			if (vCfg.getDBDriver().length() > 0) {
				DB.put(cKeyID, vCfg);
			} else {
				vCfg = null;
			}
		}
		return vCfg;
	}
}
